import requests

from common.get_token import GetToken


class EmpAPI:
    token = GetToken.get_token()
    @classmethod
    def add_emp_api(cls,body):
        add_emp_url = "http://ihrm2-test.itheima.net/api/sys/user"
        add_emp_header = {"Content-Type":"application/json", "Authorization":cls.token}
        add_resp = requests.post(url=add_emp_url,headers=add_emp_header,json=body)
        return add_resp

    @classmethod
    def query_emp_api(cls,emp_id):
        query_emp_url = f"http://ihrm2-test.itheima.net/api/sys/user/{emp_id}"
        query_emp_header = {"Authorization": cls.token}
        query_resp = requests.get(url=query_emp_url, headers=query_emp_header)
        return query_resp

    @classmethod
    def change_emp_api(cls,emp_id,body):
        change_emp_url = f"http://ihrm2-test.itheima.net/api/sys/user/{emp_id}"
        change_emp_header = {"Content-Type": "application/json", "Authorization": cls.token}
        change_resp = requests.put(url=change_emp_url, headers=change_emp_header, json=body)
        return change_resp

    @classmethod
    def delete_emp_api(cls,emp_id):
        delete_emp_url = f"http://ihrm2-test.itheima.net/api/sys/user/{emp_id}"
        delete_emp_header = {"Authorization": cls.token}
        delete_resp = requests.delete(url=delete_emp_url, headers=delete_emp_header)
        return delete_resp


if __name__ == '__main__':
    print(EmpAPI.token)